<HTML>
 <HEAD>
  <TITLE>拦截器使用示例Observable.capture</TITLE>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <link rel="stylesheet" type="text/css" href="../../ext-4.0/resources/css/ext-all.css" />
  <script type="text/javascript" src="../../ext-4.0/bootstrap.js"></script>
  <script type="text/javascript" src="../../ext-4.0/locale/ext-lang-zh_CN.js"></script>
  <script type="text/javascript">
	//继承自Ext.util.Observable
	var Person = Ext.extend(Ext.util.Observable,{
		constructor : function(name){
		   this.name = name;
		   this.say = function(){
				this.fireEvent('onSay',this.name);//激发自定义事件
		   }
		   this.addEvents({//加入自定义事件
			  "onSay" : true
		   });
		}
	});
	var per = new Person('tom');//创建对象
		
	per.addListener('onSay',handler);//为自定义事件绑定处理函数
	function handler(){//事件处理函数
		alert('发生了自定义事件');
	}
	//为per对象添加拦截器
	Ext.util.Observable.capture(per,captureFunction);
	//拦截函数
	function captureFunction(eventName){
		if(eventName == 'onSay'){//事件名称是onSay则返回false终止事件的执行
			alert("拦截事件：“"+eventName+"”。");
			return false;
		}
		return true;
	}
  </script>
 </HEAD>
 <BODY>
	<input type='button' value='say' onclick='per.say()'>
 </BODY>
</HTML>
